package com.api.shopapi.mapper;

import com.api.shopapi.entity.UserPrinter;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface UserPrinterMapper {

    @Insert("insert into user_printer (" +
            "UserPrinterCode," +
            "UserCode," +
            "SmallTicketUSB," +
            "SmallTicketUSBStatus," +
            "SmallTicketIP," +
            "SmallTicketIPStatus," +
            "KitchenIP," +
            "KitchenIPStatus," +
            "LabelUSB," +
            "LabelUSBStatus," +
            "LabelIP," +
            "LabelIPStatus" +
            ") " +
            "values " +
            "(" +
            "#{userPrinter.UserPrinterCode}," +
            "#{userPrinter.UserCode}," +
            "#{userPrinter.SmallTicketUSB}," +
            "#{userPrinter.SmallTicketUSBStatus}," +
            "#{userPrinter.SmallTicketIP}," +
            "#{userPrinter.SmallTicketIPStatus}," +
            "#{userPrinter.KitchenIP}," +
            "#{userPrinter.KitchenIPStatus}," +
            "#{userPrinter.LabelUSB}," +
            "#{userPrinter.LabelUSBStatus}," +
            "#{userPrinter.LabelIP}," +
            "#{userPrinter.LabelIPStatus}" +
            ")" )
    int insert(@Param("userPrinter") UserPrinter userPrinter);


    @Delete("delete from user_printer where userPrinterCode=#{userPrinterCode}")
    int delete(@Param("userPrinterCode") String userPrinterCode);


    @Update("update user_printer set " +
            " SmallTicketUSB=#{userPrinter.SmallTicketUSB}," +
            " SmallTicketUSBStatus=#{userPrinter.SmallTicketUSBStatus}," +
            " SmallTicketIP=#{userPrinter.SmallTicketIP}," +
            " SmallTicketIPStatus=#{userPrinter.SmallTicketIPStatus}," +
            " KitchenIP=#{userPrinter.KitchenIP}," +
            " KitchenIPStatus=#{userPrinter.KitchenIPStatus}," +
            " LabelUSB=#{userPrinter.LabelUSB}," +
            " LabelUSBStatus=#{userPrinter.LabelUSBStatus}," +
            " LabelIP=#{userPrinter.LabelIP}," +
            " LabelIPStatus=#{userPrinter.LabelIPStatus}" +
            " where userPrinterCode=#{userPrinter.userPrinterCode}")
    int update(@Param("userPrinter") UserPrinter userPrinter);


    @Select("select * from user_printer where userPrinterCode=#{userPrinterCode} limit 1")
    UserPrinter getByUserPrinterCode(@Param("userPrinterCode") String userPrinterCode);

    @Select("select * from user_printer where userCode=#{userCode} limit 1")
    UserPrinter getByUserCode(@Param("userCode") String userCode);

}
